//
//  SinaComposePictureCell.m
//  MySinaWeiboProjectForOC
//
//  Created by apple on 2016/11/28.
//  Copyright © 2016年 WangChen. All rights reserved.
//

#import "SinaComposePictureCell.h"



@interface SinaComposePictureCell ()

@property (nonatomic,weak) UIButton *addBtn;
@property (nonatomic,weak) UIButton *closeBtn;

@end


@implementation SinaComposePictureCell


//重写
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //设置界面
        [self setupUI];
    }
    return self;
}

//设置界面
-(void)setupUI{

    //设置添加图片按钮
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [addBtn setBackgroundImage:[UIImage imageNamed:@"compose_pic_add"] forState:UIControlStateNormal];
    [addBtn setBackgroundImage:[UIImage imageNamed:@"compose_pic_add_highlighted"] forState:UIControlStateHighlighted];
    _addBtn = addBtn;
    [addBtn addTarget:self action:@selector(clickAddBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:addBtn];
    
    //设置约束
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    //设置关闭按钮
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setImage:[UIImage imageNamed:@"compose_photo_close"] forState:UIControlStateNormal];
    [closeBtn sizeToFit];
    _closeBtn = closeBtn;
    [closeBtn addTarget:self action:@selector(clickCloseBtn) forControlEvents:UIControlEventTouchUpInside];
    closeBtn.hidden = YES;
    [self.contentView addSubview:closeBtn];
    
    //给关闭按钮设置约束
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.trailing.equalTo(self.contentView);
    }];
    
}


#pragma mark
#pragma mark - 点击按钮触发方法
-(void)clickAddBtn{
    
    if(self.addBtn.imageView.image){
        NSLog(@"已经添加图片");
        return;
    }
    
    [self.delegate addBtndidClick:self];
}

-(void)clickCloseBtn{
    [self.delegate closeBtnDidClick:self];
}



#pragma mark
#pragma mark - image set方法
-(void)setImage:(UIImage *)image{
    
    _image = image;
    [self.addBtn setImage:image forState:UIControlStateNormal];
    if(image){
        self.closeBtn.hidden = NO;
    }else{
        self.closeBtn.hidden = YES;
    }
    
}



@end
